<template>
  <section class="course-carousel">
    <el-carousel height="378px" trigger="click" indicator-position="outside">
      <el-carousel-item v-for="course in courses" :key="course.id">
        <div
          class="course-carousel__slide"
          role="button"
          tabindex="0"
          @click="handleSelect(course.id)"
          @keyup.enter="handleSelect(course.id)"
          @keyup.space.prevent="handleSelect(course.id)"
        >
          <div class="course-carousel__info">
            <span v-if="course.highlightTag" class="course-carousel__badge">{{ course.highlightTag }}</span>
            <h1>{{ course.title }}</h1>
            <p>{{ course.description }}</p>
            <div class="course-carousel__meta">
              <span>{{ course.instructorName }}</span>
              <span class="course-carousel__price">{{ course.priceLabel }}</span>
            </div>
          </div>
          <div class="course-carousel__media">
            <img :src="course.coverImage" :alt="course.title" loading="lazy" />
          </div>
        </div>
      </el-carousel-item>
    </el-carousel>
  </section>
</template>

<script setup lang="ts">
import type { CourseItem } from '../../types/course/Course.ts'

defineOptions({
  name: 'CourseCarousel',
})

const emit = defineEmits<{
  (e: 'course-select', courseId: string): void
}>()

defineProps<{
  courses: CourseItem[]
}>()

const handleSelect = (courseId: string) => {
  emit('course-select', courseId)
}
</script>

<style scoped>
.course-carousel {
  border-radius: 32px;
  overflow: hidden;
  background: linear-gradient(135deg, #f5f8ff 0%, #fef5ff 100%);
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.08);
}


.course-carousel :deep(.el-carousel__container) {
  border-radius: 32px;
}

.course-carousel__slide {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  align-items: center;
  gap: 32px;
  padding: 56px 64px;
  min-height: 360px;
  cursor: pointer;
}

.course-carousel__info {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 640px;
}

.course-carousel__badge {
  align-self: flex-start;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(60, 101, 245, 0.12);
  color: #3c65f5;
  font-weight: 600;
  font-size: 14px;
}

.course-carousel__info h1 {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.2;
  color: #1f2937;
}

.course-carousel__info p {
  font-size: 18px;
  color: #4b5563;
  line-height: 1.6;
}

.course-carousel__meta {
  display: flex;
  gap: 16px;
  align-items: center;
  font-weight: 600;
  color: #374151;
}

.course-carousel__price {
  color: #10b981;
}

.course-carousel__media {
  display: flex;
  justify-content: center;
}

.course-carousel__media img {
  width: 100%;
  max-width: 420px;
  border-radius: 28px;
  object-fit: cover;
  box-shadow: 0 20px 45px rgba(60, 101, 245, 0.18);
}

@media (max-width: 960px) {
  .course-carousel__slide {
    padding: 48px 32px;
  }

  .course-carousel__info h1 {
    font-size: 30px;
  }
}

@media (max-width: 640px) {
  .course-carousel__slide {
    padding: 40px 24px;
  }

  .course-carousel__info {
    max-width: 100%;
  }

  .course-carousel__info h1 {
    font-size: 26px;
  }

  .course-carousel__info p {
    font-size: 16px;
  }
}
</style>
